The present invention relates to a variable bit-rate encoding device. More particularly, the present invention relates to a two-pass-system encoding device that encodes moving picture (image) data at a variable bit-rate.
The moving image data encoding technique has a constant bit-rate encoding method and a variable bit-rate encoding method.
FIG. 3 is a diagram illustrating the relationship between time and encoded bit-rate in the case where a certain set of moving image data is subjected to the constant bit-rate encoding and the variable bit-rate encoding.
In the constant bit rate encoding shown in FIG. 3, the bit rate is always constant. On the other hand, in the variable bit-rate encoding, the bit rate varies due to the complexity of image data. Since the duration (a) is for image data relatively difficult to be handled, encoding is performed at a high bit rate. Since the duration (b1) and the duration (b2) are for image data relatively easy to be handled, encoding is performed at a low bit rate.
In the variable bit-rate encoding, a large quantity of codes is allocated to complicated images while a small quantity of codes is allocated to simple images. Consequently, moving image data can be encoded with the image quality maintained uniformly.
In the constant bit-rate encoding, information may not be sufficient in the duration (a) in which much information are produced as shown in the area A shown in FIG. 3. Information may be encoded redundantly in the duration (b1) or (b2) in which less information are produced, as shown in the area B shown in FIG. 3.
Accordingly, it may be generally said that the variable bit-rate encoding method is effective, in regard to the image quality.
The so-called two-pass system variable bit rate encoding scheme is known as one of variable bit-rate encoding schemes.
In the two-pass system variable bit-rate encoding method, an information amount generated per unit section of all sequences of moving images is analyzed in the first pass and a target code amount for each unit section is allocated based on the analyzed result. Thereafter, while the generated code amount for each unit section in the second pass is controlled to bring close to a target code amount, an actual encoding is performed.
As described above, the two-path system variable bit-rate encoding method is characterized in that an ideal variable bit rate control is performed because a target code amount for each unit section is allocated by analyzing the information generation amount of all sequences for a moving image, prior to an actual encoding.
FIG. 11 is a block diagram illustrating a conventional two-pass variable bit-rate encoding device.
As shown in FIG. 11, the conventional variable bit rate encoding device consists of an input buffer 202 with an input terminal 201, a subtracter 203, a DCT (Discrete Cosine Transform) unit 204, a quantizer 205, a variable length encoder 206, an inverse quantizer 207, an inverse DCT unit 208, an adder 209, a frame memory 210, a motion compensator 211, a motion vector searcher 212, a code amount allocator 213, a code amount controller 214, and an output terminal 215.
Image data input from the input terminal 201 is supplied in line units to the input buffer 202.
As shown in FIG. 4, input image data to encoded as one of an I (Intra) frame, a P (Prediction) frame, or a B (Bi-directional) frame.
I frame is a frame encoded in an inter frame process only and does not undergo an inter motion compensation frame predictive encoding. I frame also is used as a reference frame for the successive P and B frames.
P frame is a reference frame an I or P frame in the forward direction on the time axis and is used to perform an inter motion compensation frame predictive encoding in one direction. P frame is used as a reference frame for the other successive P and B frames.
B frame is a reference frame for the I or P frame in the forward direction and backward direction on the time axis and is used to perform an inter motion compensation predictive encoding in two directions. The B frame is not used in the reference frame of other frame.
The input buffer 202 rearranges input image data in an encoding order and outputs the output signal to the subtracter 203 and the motion vector searcher 212 in encoded block units or in macroblock units.
In FIG. 4 as previously described, the third P frame, for example, is encoded earlier than the first and second B frames to use the third P frame as a reference frame. Hence, the input buffer 202 rearranges images.
FIG. 5 shows the rearrangement operation. The image data input shown with input order in FIG. 5 are supplied in the order shown with encoding order in FIG. 5.
The macroblock is a minimum unit for a motion compensation prediction and corresponds to image data of 16xc3x9716 pixels. The macroblock data is configured of the brightness block Y of 8xc3x973 pixels and the color-difference blocks Cr and Cb. The total block number depends on a color-difference data thinned-out type.
When the thinned-out type is 4:2:0, as shown in FIG. 6A, there are 6 blocks including 4 brightness blocks Y, one color-difference block Cr, and one color-difference block Cb. When the thinned-out type is 4:2:2. as shown in FIG. 6B, there are 8 blocks including 4 brightness blocks Y, 2 color-difference blocks Cr, and 2 color-difference blocks Cb. When the thinned-out type is 4:4:4. as shown in FIG. 6C. there are 12 blocks including 4 brightness blocks Y, 4xe2x80x2 color-difference blocks Cr and 4 color-difference blocks Cb.
The subtracter 203 receives compressed block data output from the input buffer 202 and reference macroblock data motion-compensated with the motion compensator 211 and then outputs these interframe predictive error signals to the DCT unit 204.
The DCT unit 204 subjects each interframe predictive error signal to a DCT process to separate it into horizontal and vertical frequency components. Thus, the DCT unit 204 outputs the horizontal and vertical frequency components to the quantizer 205.
The quantizer 205 quantizes the output from the DCT unit 204 to reduce the code amount. Thus, the quantizer 205 outputs the result to the variable length encoder 206 and the inverse quantizer 207. The quantizer 205 performs a fixed quantization with the quantization step size of a fixed value in the first pass tentative encoding. The quantizer 205 also performs a fixed quantization with the quantization step size set by the code amount controller 214 in an actual second pass encoding.
The inverse quantizer 207 inverse-quantizes the output of the quantizer 205 and then outputs the result to the inverse DCT unit 208.
The inverse DCT unit 208 subjects the output of the inverse quantizer 207 to an inverse DCT process and then outputs the result to the adder 209.
The adder 209 adds the reference macroblock data motion-compensated by the motion compensator 211 and the output of the inverse DCT unit 208. Then, the adder 209 outputs the resultant sum to the frame memory 210.
The frame memory 210 outputs macroblock data acting as new reference frames data to the motion compensator 211 and the motion vector searcher 212.
The motion vector searcher 212 receives the macroblock data of a compressed frame from the input buffer 202 as well as the macroblock data of a reference frame from the frame memory 210. The motion vector seacher 212 implements the block matching between the input macroblock data sets to obtain a motion vector between the reference frame and the compressed frames and then outputs it to the motion compensator 211.
The frame memory 210 provides reference frame data to the motion compensator 211. The motion compensator 211 motion-compensates the reference frame data with the motion vector from the motion vector searcher 212 to create reference macro block data. Thus, the motion compensator 211 supplies it to the subtracter 203.
The variable length encoder 206 subjects the output of the quantizer 205 to a variable length encoding. The result is supplied to the code amount allocator 213 in the first pass tentative encoding and to the code amount controller 213 in the second pass tentative encoding. At the same time, the result is output via the output terminal 215.
The variable length encoder 206 inputs codes generated in the first pass tentative encoding to the code amount allocator 213. The code amount allocator 213 stores the code amount generated in the first pass tentative encoding for each unit section and determines a target code amount, allocated in each unit section in an actual second pass encoding at the time when the first pass tentative encoding has been ended.
FIG. 7 is a diagram showing generated code amounts for each unit section in the first pass tentative encoding. As shown in FIG. 7, the B section representing a relatively simple scene corresponds to a small generation code amount. The A section representing a relatively difficult scene corresponds to a large generation code amount. Consequently, in an actual second pass encoding, a larger target code amount is allocated to the A section while a smaller target code amount is allocated to the B section.
The code amount controller 214 adjusts the quantized step size to bring the code amount generated in an actual second pass encoding close to the target code amount set in the first pass encoding and then outputs the result to the quantizer 205. That is, the code amount controller 214 determine a suitable quantized step size based on the difference between a target code amount for each unit section input from the code amount allocator 213 and an actually generated code amount input from the variable length encoder 206.
A typical example of the above-mentioned two-pass system variable bit rate encoding device is disclosed in JP-A No. 141298/1994 and JP-A No. 93537/1997.
However, in such a two-pass system variable bit rate encoding device, a sequence of encoding steps including the first pass tentative encoding and the second pass actual encoding have to be repeated twice. Accordingly, the problem is that encoding moving images at a constant bit rate requires the processing time twofold.
The present invention is made to solve the above-mentioned problems.
The objective of the invention is to provide a novel two-pass system variable bit rate encoding device that can solve the problems occurring in the prior art.
The objective of the present invention is achieved by a two-pass system variable bit-rate encoding device, wherein moving picture data is encoded at a variable bit rate, comprising first encoding means for calculating a power for each unit section of a predictive error, using correlation between the power of a predictive error in inter motion compensation frame prediction and a generated code amount in a first pass, and for determining a target code amount allocated to each unit section in a second pass encoding, according to the magnitude of the predictive error power of the whole image data and the magnitude of the predictive error power for each unit section; and second encoding means for performing an encoding process while controlling a generated code amount to adjust the target code amount for each unit section in the second pass.
In the variable bit-rate encoding device according to the present invention, a target code amount is allocated in proportional distribution based on a predictive error power in each unit section and based on a predictive error power of the whole image data.
Moreover, in the variable bit-rate encoding device according to the present invention, a target code amount is compensated to set a coded rate within a predetermined range based on a predictive error power in each unit section and based on a predictive error power of the whole image data.
A motion vector value, which is obtained by searching a, motion vector for inter motion compensation frame prediction in the first pass by means of the first encoding means, is used without any change during a second pass encoding by the second encoding means. Thus, the motion vector searching process in the second pass is omitted.
The first encoding means comprises a first subtracter for receiving compressed macroblock image data rearranged in an encoding frame order by an input buffer and reference macroblock image data motion-compensated by a first motion compensator (to be defined later) and then calculating an inter frame predictive error signal of the two sets of image data; a first frame memory for storing macroblock image data output from the input buffer; a motion vector searcher for receiving the reference macroblock image data from the first frame memory and compressed macroblock image data from the input buffer, and then performing a block matching process to macroblock data within a research range of the reference macroblock image data, thus obtaining a motion vector; a first motion compensator for receiving the motion vector from the motion vector searcher and then creating the reference macroblock image data motion-compensated; and a code-amount allocator for obtaining a power of each GOP (Group of Pictures), the GOP being configured of a plurality of frames of the inter frame predictive error signal supplied from the first subtracter, and then determining a target code amount allocated to each GOP in an actual encoding process by the second encoding means according to the power of a predictive error signal for each GOP.
The second encoding means comprises a second subtracter for receiving compressed macroblock image data rearranged in an encoding frame order by an input buffer and reference macroblock image data motion-compensated by a second motion compensator (to be defined later) and then calculating an inter frame predictive error signal of the two sets of image data; a DCT unit for performing a DCT process of an inter frame predictive error signal output from the second subtracter: a quantizer for quantizing a DCT output from the DCT unit; an inverse quantizer for inverse quantizing a quantized output from the quantizer; an inverse DCT unit for performing an inverse DCT unit of an output from the inverse quantizer; an adder for adding an output from the inverse DCT unit and reference macroblock image data motion-compensated by a second motion compensator (to be defined later); a motion vector memory for storing the motion vector output from the motion vector searcher; a second frame memory for storing an output from the adder; a second motion compensator for motion-compensating reference frame data supplied from the second frame memory with a motion vector from the motion vector memory and then supplying the result to the second subtracter and the adder; a variable length encoder for variable-length-encoding a quantized output from the quantizer; and a code-amount allocator for controlling a code amount based on a code amount actually generated from the variable-length encoder and based on a target code amount for each unit section output from the code amount allocater in the first encoding means.
The first encoding means further comprises a motion vector decision unit for supplying an output from the motion vector searcher to the code-amount allocator. The motion vector decision unit decides a motion vector movement output from the motion vector searcher and adjusts a target code amount to be allocated according to the motion vector movement.
Moreover, in the variable bit rate encoding device according to the present invention, the first and second subtracters may be integrated as one piece. The first and second motion compensators may be integrated as one piece. The first and second frame memories may be integrated as one piece. Thus, each one-piece component can be shared in time divisional mode, using the first encoding means and the second encoding means.